package com.youku.controls
{
   import com.youku.plugins.controlbarV4.ControlBarFacade;
   import com.youku.events.PluginEvent;
   import com.youku.conductor.ConductorState;
   import com.youku.events.PlayerControlEvent;
   import com.youku.data.PlayerContext;
   import com.youku.PlayerConfig;
   import com.youku.events.ViewManagerEvent;
   import com.youku.data.PlayerConstant;
   import com.youku.GlobalService;
   import com.youku.GlobalServiceKeys;
   
   public class ControlbarV4Controller extends BasePluginController
   {
      
      public function ControlbarV4Controller() {
         super();
         this._controlbarFacade = ControlBarFacade.getInstance();
         this._controlbarFacade.init(viewManager.controlsLayer,playerProxy);
         GlobalService.addService(GlobalServiceKeys.CONTROL_BAR_FACADE,this._controlbarFacade);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CHANGE_FULLSCREEN,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_DRAG_BEGIN,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_DRAG_DRAGGING,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_DRAG_FINISH,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_PAUSE,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_RESUME,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_SEEK,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CHANGE_SCREEN_MODE,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CHANGE_VOLUME,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CHANGE_QUALITY,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_TOOLBOX,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_PRE_VIDEO,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_PROGRAM_LIST,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_NEXT_VIDEO,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_LOGO,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_CAPTION,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_THREED,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_LOOP,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_CLICK_ROTATE,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_BAR_HEIGHT_CHANGED,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_SHARE,this.onControlBarEvent);
         playerProxy.addEventListener(PluginEvent.CONTROL_PREVIEW_SHARE,this.onControlBarEvent);
      }
      
      private var _controlbarFacade:ControlBarFacade;
      
      private function onControlBarEvent(param1:PluginEvent) : void {
         var _loc9_:* = false;
         var _loc10_:* = false;
         var _loc11_:* = NaN;
         var _loc12_:* = NaN;
         var _loc2_:Number = 0;
         var _loc3_:* = false;
         var _loc4_:* = false;
         var _loc5_:* = -1;
         var _loc6_:* = false;
         var _loc7_:Number = 0;
         var _loc8_:* = "";
         switch(param1.type)
         {
            case PluginEvent.CONTROL_BAR_CHANGE_FULLSCREEN:
               changeFullScreenMode();
               break;
            case PluginEvent.CONTROL_BAR_DRAG_BEGIN:
               _loc2_ = param1.data.time;
               if(conductor.currentState == ConductorState.VIDEO)
               {
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_DRAGGING,{"dragging":true}));
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_PAUSE,{"useraction":false}));
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_MOCKSEEK,{"time":_loc2_}));
               }
               break;
            case PluginEvent.CONTROL_BAR_DRAG_DRAGGING:
               _loc2_ = param1.data.time;
               if(conductor.currentState == ConductorState.VIDEO)
               {
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_MOCKSEEK,{"time":_loc2_}));
               }
               break;
            case PluginEvent.CONTROL_BAR_DRAG_FINISH:
               _loc2_ = param1.data.time;
               if(conductor.currentState == ConductorState.VIDEO)
               {
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_DRAGGING,{"dragging":false}));
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_SEEK,{"time":_loc2_}));
               }
               else if(conductor.currentState == ConductorState.VIDEO_END)
               {
                  conductor.replay(_loc2_);
               }
               
               break;
            case PluginEvent.CONTROL_BAR_PAUSE:
               if(conductor.currentState == ConductorState.VIDEO)
               {
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_PAUSE,{"useraction":true}));
               }
               break;
            case PluginEvent.CONTROL_BAR_RESUME:
               facadeManager.onResume();
               break;
            case PluginEvent.CONTROL_BAR_SEEK:
               _loc2_ = param1.data.time;
               _loc3_ = param1.data.jump;
               if(_loc3_)
               {
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_SEEK,{"time":_loc2_}));
               }
               else
               {
                  playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_MOCKSEEK,{"time":_loc2_}));
               }
               break;
            case PluginEvent.CONTROL_BAR_CHANGE_SCREEN_MODE:
               _loc5_ = param1.data.mode;
               _loc6_ = param1.data.tween;
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_CHANGE_SCREEN_MODE,
                  {
                     "mode":_loc5_,
                     "tween":_loc6_
                  }));
               break;
            case PluginEvent.CONTROL_BAR_CHANGE_QUALITY:
               _loc8_ = param1.data.quality;
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.CORE_CHANGE_QUALITY,{"quality":_loc8_}));
               break;
            case PluginEvent.CONTROL_BAR_CHANGE_VOLUME:
               _loc7_ = param1.data.volume;
               PlayerContext.volume = _loc7_;
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.COMMON_CHANGE_VOLUME,{"volume":_loc7_}));
               break;
            case PluginEvent.CONTROL_BAR_TOOLBOX:
               facadeManager.showToolBox(param1.data.type);
               break;
            case PluginEvent.CONTROL_BAR_CLICK_PRE_VIDEO:
               facadeManager.playPreVideoList();
               break;
            case PluginEvent.CONTROL_BAR_CLICK_NEXT_VIDEO:
               facadeManager.playNextVideoList();
               break;
            case PluginEvent.CONTROL_BAR_CLICK_PROGRAM_LIST:
               facadeManager.showProgramList();
               break;
            case PluginEvent.CONTROL_BAR_CLICK_LOGO:
               if((isOuterPlayer) && (isLogoLinkout))
               {
                  gotoVideoSiteURL();
               }
               break;
            case PluginEvent.CONTROL_BAR_HEIGHT_CHANGED:
               PlayerConfig.controlBarHeight = param1.data.cheight;
               _loc9_ = param1.data.fullscreen;
               viewManager.dispatchEvent(new ViewManagerEvent(ViewManagerEvent.PLAYER_SIZE_CHANGED,_loc9_));
               break;
            case PluginEvent.CONTROL_BAR_CLICK_THREED:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.BEFORE_SHOW_PANELS,{"panel":PlayerConstant.PANEL_THREED}));
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.SHOW_EX_PLUGIN,{"panel":PlayerConstant.PANEL_THREED}));
               break;
            case PluginEvent.CONTROL_BAR_CLICK_CAPTION:
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.BEFORE_SHOW_PANELS,{"panel":PlayerConstant.PANEL_CAPTION}));
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.SHOW_EX_PLUGIN,{"panel":PlayerConstant.PANEL_CAPTION}));
               break;
            case PluginEvent.CONTROL_BAR_CLICK_LOOP:
               _loc10_ = param1.data.loop;
               playerProxy.fsoProxy.saveLoopSetting(_loc10_);
               break;
            case PluginEvent.CONTROL_BAR_CLICK_ROTATE:
               _loc11_ = param1.data.angle as Number;
               playerProxy.dispatchEvent(new PlayerControlEvent(PlayerControlEvent.PLAYER_ROTATION_CHANGED,{"angle":_loc11_}));
               break;
            case PluginEvent.CONTROL_SHARE:
               facadeManager.showShareBox("share");
               break;
            case PluginEvent.CONTROL_PREVIEW_SHARE:
               _loc12_ = param1.data.time;
               facadeManager.showShareBox("preview",_loc12_);
               break;
         }
      }
   }
}
